//=======================================================================
# hc05 source
//74HC05: Hex Inverter (Open Drain)
//typical propagation delay values from Fairchild datasheet, January 1998
//=======================================================================
INPUTS VCC, GND, IN;
OUTPUTS VCC_LD, IN_LD, OUT;
INTEGERS tblIndex;
REALS tt_2, tt_4_5, tt_6, tt_val,
      tpzl_2, tpzl_4_5, tpzl_6,
      tplz_2, tplz_4_5, tplz_6,
      rol_4_5, rol_6,
      rin_val, ricc_val,
      vcc_val;

PWR_GND_PINS(VCC, GND);    //set pwr_param and gnd_param values
SUPPLY_MIN_MAX(2, 6);      //check for min supply=2 and max supply=6
VOL_VOH_MIN(0.1,-0.1,0.1); //set min vol_param=gnd_param+0.1, max voh_param=pwr_param-0.1;
VIL_VIH_PERCENT(33,66);    //VIL=33% of supply voltage, VIH=66% of supply voltage

IO_PAIRS(IN:IN_LD);    //input output pairs


IF (init_sim) THEN
  BEGIN
    //MESSAGE("time\tINA\tINB\tOUT");

    //NOTE: both ttlh and tthl are the same value
    tt_2   = (MIN_TYP_MAX(tt_param: NULL, 30n, 75n)); //datasheet values for 2V operation
    tt_4_5 = (MIN_TYP_MAX(tt_param: NULL, 8n, 15n));  //datasheet values for 4.5V operation
    tt_6   = (MIN_TYP_MAX(tt_param: NULL, 7n, 13n));  //datasheet values for 6V operation

    tpzl_2   = (MIN_TYP_MAX(tp_param: NULL, 30n, 75n)); //datasheet values for 2V operation
    tpzl_4_5 = (MIN_TYP_MAX(tp_param: NULL, 8n, 15n));  //datasheet values for 4.5V operation
    tpzl_6   = (MIN_TYP_MAX(tp_param: NULL, 7n, 13n));  //datasheet values for 6V operation

    tplz_2   = (MIN_TYP_MAX(tp_param: NULL, 30n, 90n)); //datasheet values for 2V operation
    tplz_4_5 = (MIN_TYP_MAX(tp_param: NULL, 13n, 18n));  //datasheet values for 4.5V operation
    tplz_6   = (MIN_TYP_MAX(tp_param: NULL, 12n, 15n));  //datasheet values for 6V operation

    //Open Drain Oputput
    roh_param = (1e12);

    //IOLmax = 4mA @ Vcc=4.5v and VOLtyp=0.2: routtyp=Voltyp/IOLmax=0.2/4m=50 
    //IOLmax = 4mA @ Vcc=4.5v and VOLmax=0.26: routmin=Volmax/IOLmax=0.26/4m=65     
    rol_4_5 = (MIN_TYP_MAX(tp_param: 65, 50, NULL));

    //IOLmax = 5.2mA @ Vcc=6v and VOLtyp=0.2: routtyp=Voltyp/IOLmax=0.2/5.2m=38.46 
    //IOLmax = 5.2mA @ Vcc=6v and VOLmax=0.26: routmin=Volmax/IOLmax=0.26/5.2m=50     
    rol_6 = (MIN_TYP_MAX(tp_param: 50, 38.46, NULL));


    //Iin(max) = 0.1uA @ 6V.   ril=(Vin-vol_param)/IIHmax = 5.9/0.1u = 59e6
    //Iin(max) = -0.1uA @ 0V.  rih=(voh_param-Vin)/IILmax = 5.9/0.1u = 59e6
    rin_val= (MIN_TYP_MAX(ld_param: NULL, NULL, 59e6));

    //Icc(max) = 2uA @ 6V.  ricc(max)= 6/2u = 3e6
    ricc_val=(MIN_TYP_MAX(i_param: NULL, NULL, 3e6));

    STATE OUT = ZERO;  //initialise output
    EXIT;
  END;

vcc_val   = (pwr_param - gnd_param);
rol_param = (PWL_TABLE(vcc_val: 4.5, rol_4_5, 6, rol_6));
tt_val    = (PWL_TABLE(vcc_val: 2, tt_2, 4.5, tt_4_5, 6, tt_6));

DRIVE OUT = (v0=vol_param, v1=gnd_param, ttlh=tt_val, tthl=tt_val);
LOAD IN_LD = (v0=vol_param, r0=rin_val, v1=voh_param, r1=rin_val, io=1e12, t=1p);

TABLE tblIndex
IN    OUT
0     H
1     L;

//MESSAGE("%fs\t%d\t%d\t%d",present_time,INA,INB,OUT);

LOAD VCC_LD = (v0=gnd_param, r0=ricc_val, t=1p);

DELAY OUT = 
  CASE (TRAN_XL):(PWL_TABLE(vcc_val: 2, tpzl_2, 4.5, tpzl_4_5, 6, tpzl_6))
  CASE (TRAN_LX):(PWL_TABLE(vcc_val: 2, tplz_2, 4.5, tplz_4_5, 6, tplz_6))
END;

EXIT;